package csvParser;

import java.io.*;
import java.util.*;

public class CSVParser {
	
	private File myDoc;
	private File doc_mail;
	
	private ArrayList<String> headers;
	private ArrayList<String> mail_headers;

	private ArrayList<String> oneData;
	private ArrayList<Integer> the_size;
	private ArrayList<String> data_mail;
	
	private ArrayList<String> msgs;
	
	private ArrayList<String> documents;
	private ArrayList<Integer> documents_sizes;
	
	private ArrayList<String> excels;
	private ArrayList<Integer> excels_sizes;
	
	private ArrayList<String> ppt;
	private ArrayList<Integer> ppt_sizes;
	
	private ArrayList<String> images;
	private ArrayList<Integer> images_sizes;
	
	private ArrayList<String> video;
	private ArrayList<Integer> video_sizes;
	
	private ArrayList<String> mp3;
	private ArrayList<Integer> mp3_sizes;
	
	private ArrayList<String> pdf;
	private ArrayList<Integer> pdf_sizes;
	
	private ArrayList<String> torrent;
	private ArrayList<Integer> torrent_sizes;

	public CSVParser(){
		
		myDoc = new File("/Users/giuliabiffi/Desktop/timeline.csv");
		
		headers = new ArrayList<String>();
		
		oneData = new ArrayList<String>();
		the_size = new ArrayList<Integer>();
		data_mail = new ArrayList<String>();
		
		documents = new ArrayList<String>();
		documents_sizes = new ArrayList<Integer>();
		
		excels = new ArrayList<String>();
		excels_sizes = new ArrayList<Integer>();
		
		ppt = new ArrayList<String>();
		ppt_sizes = new ArrayList<Integer>();
		
		images = new ArrayList<String>();
		images_sizes = new ArrayList<Integer>();
		
		video = new ArrayList<String>();
		video_sizes = new ArrayList<Integer>();
		
		mp3 = new ArrayList<String>();
		mp3_sizes = new ArrayList<Integer>();
		
		pdf = new ArrayList<String>();
		pdf_sizes = new ArrayList<Integer>();
		
		torrent = new ArrayList<String>();
		torrent_sizes = new ArrayList<Integer>();
			
	}
	
	public String takeOffQuotes(String input_str){
		
		if (input_str.startsWith("\"")){
			input_str = input_str.substring(1, input_str.length());
	    }
	    if (input_str.endsWith("\"")){
	    	input_str = input_str.substring(0, input_str.length() - 1);
	    }
	    
	    return input_str;
	}
	
	
	// parsing the result of slk commands fls + mactime
	public void parserCsv() throws FileNotFoundException{
		
		Scanner lineScan = new Scanner(myDoc);

		Scanner s = new Scanner(lineScan.nextLine());
	
		s.useDelimiter(",");
		
		while (s.hasNext()) {

			headers.add(s.next());

		}
		
		while (lineScan.hasNextLine()) {

			s = new Scanner(lineScan.nextLine());
			
			s.useDelimiter("\n");
			
			while (s.hasNext()) {
				
				String temp = s.next();
				
				String[] data = temp.split(",");
				
				String fileName = data[data.length-1];
				// take off quotes
				Integer size = Integer.valueOf(data[1]);
				//System.out.println(size);
				
				if(!oneData.contains(fileName)) {
					oneData.add(takeOffQuotes(fileName));
					the_size.add(size);
				}
				
			}

		}
		
		System.out.println(headers.get(headers.size()-1));
		
		/*for(String a : the_size){
			
			System.out.println("headers: "+a);
		}*/
		
/*		for(String b : oneDdata){
			
//			String[] data = temp.split(",");
//			//String[] pathExploded = data[data.length-2];
//			String fileName = data[data.length-1];
//			System.out.println(fileName);
			System.out.println("data: "+b);
			//System.out.println();
		}
		*/
	}

	
public void createCSVs() {
		
	for(int i=0; i<oneData.size(); i++) {
		
		String temp = oneData.get(i);
		int intr = the_size.get(i);
		
		if(temp.endsWith(".doc") || temp.endsWith(".doc (deleted)") || temp.endsWith(".txt") || temp.endsWith(".txt (deleted)") || temp.endsWith(".rtf") || temp.endsWith(".rtf (deleted)") || temp.endsWith(".docx") || temp.endsWith(".docx (deleted)") || temp.endsWith(".xml") || temp.endsWith(".xml (deleted)") || temp.endsWith(".xmlx") || temp.endsWith(".xmlx (deleted)") || temp.endsWith(".odt") || temp.endsWith(".odt (deleted)") || temp.endsWith(".pages") || temp.endsWith(".pages (deleted)")) {
			documents.add(temp);
		/*if(temp.endsWith(".doc\"") || temp.endsWith(".doc (deleted)\"") || temp.endsWith(".txt\"") || temp.endsWith(".txt (deleted)\"") || temp.endsWith(".rtf\"") || temp.endsWith(".rtf (deleted)\"") || temp.endsWith(".docx\"") || temp.endsWith(".docx (deleted)\"") || temp.endsWith(".xml\"") || temp.endsWith(".xml (deleted)\"") || temp.endsWith(".xmlx\"") || temp.endsWith(".xmlx (deleted)\"") || temp.endsWith(".odt\"") || temp.endsWith(".odt (deleted)\"") || temp.endsWith(".pages\"") || temp.endsWith(".pages (deleted)\"")) {
			documents.add(temp);*/
			//documents_sizes.add(the_size.get(i));
			documents_sizes.add(intr);
		} else if(temp.endsWith(".xls") || temp.endsWith(".xls (deleted)") || temp.endsWith(".xlsx") || temp.endsWith(".xlsx (deleted)") || temp.endsWith(".numbers") || temp.endsWith(".numbers (deleted)") || temp.endsWith(".ods") || temp.endsWith(".ods (deleted)") || temp.endsWith(".sdc") || temp.endsWith(".sdc (deleted)") || temp.endsWith(".123") || temp.endsWith(".123 (deleted)")) {
			excels.add(temp);
			excels_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".ppt") || temp.endsWith(".ppt (deleted)") || temp.endsWith(".pptx") || temp.endsWith(".pptx (deleted)") || temp.endsWith(".odp") || temp.endsWith(".odp (deleted)") || temp.endsWith(".keynote") || temp.endsWith(".keynote (deleted)")) {
			ppt.add(temp);
			ppt_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".jpg") || temp.endsWith(".jpg (deleted)") || temp.endsWith(".jpeg") || temp.endsWith(".jpeg (deleted)") || temp.endsWith(".gif") || temp.endsWith(".gif (deleted)") || temp.endsWith(".png") || temp.endsWith(".png (deleted)") || temp.endsWith(".bmp") || temp.endsWith(".bmp (deleted)") || temp.endsWith(".tiff") || temp.endsWith(".tiff (deleted)") || temp.endsWith(".jfif") || temp.endsWith(".jfif (deleted)")) {
			images.add(temp);
			images_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".avi") || temp.endsWith(".avi (deleted)") || temp.endsWith(".fla") || temp.endsWith(".fla (deleted)") || temp.endsWith(".mpeg") || temp.endsWith(".mpeg (deleted)") || temp.endsWith(".mpg") || temp.endsWith(".mpg (deleted)") || temp.endsWith(".mswmm") || temp.endsWith(".mswmm (deleted)") || temp.endsWith(".xvid") || temp.endsWith(".xvid (deleted)") || temp.endsWith(".wmv") || temp.endsWith(".wmv (deleted)") || temp.endsWith(".flv") || temp.endsWith(".flv (deleted)") || temp.endsWith(".mkv") || temp.endsWith(".mkv (deleted)") || temp.endsWith(".m4v") || temp.endsWith(".m4v (deleted)")) {
			video.add(temp);
			video_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".mp3") || temp.endsWith(".mp3 (deleted)") || temp.endsWith(".m4p") || temp.endsWith(".m4p (deleted)") || temp.endsWith(".aac") || temp.endsWith(".aac (deleted)") || temp.endsWith(".wav") || temp.endsWith(".wav (deleted)") || temp.endsWith(".mp4") || temp.endsWith(".mp4 (deleted)") || temp.endsWith(".m4a") || temp.endsWith(".m4a (deleted)") || temp.endsWith(".ogg") || temp.endsWith(".ogg (deleted)") || temp.endsWith(".wma") || temp.endsWith(".wma (deleted)") || temp.endsWith(".flac") || temp.endsWith(".flac (deleted)") || temp.endsWith(".au") || temp.endsWith(".au (deleted)") || temp.endsWith(".AIFF") || temp.endsWith(".AIFF (deleted)") || temp.endsWith(".mpc") || temp.endsWith(".mpc (deleted)") || temp.endsWith(".mid") || temp.endsWith(".mid (deleted)")) {
			mp3.add(temp);
			mp3_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".pdf") || temp.endsWith(".pdf (deleted)") ){
			pdf.add(temp);
			pdf_sizes.add(the_size.get(i));
		} else if(temp.endsWith(".torrent") || temp.endsWith(".torrent (deleted)") || temp.endsWith(".part") || temp.endsWith(".part (deleted)") ){
			torrent.add(temp);
			torrent_sizes.add(the_size.get(i));
		}

	}
}


	public ArrayList<String> getOneData(){
		return oneData;
	}
	
	public ArrayList<String> getDataMail(){
		return data_mail;
	}
	
	public ArrayList<String> getCsv(int num){
		
		switch (num) {
		case 1: return documents;
		case 2: return images;
		case 3: return excels;
		case 4: return ppt;
		case 5: return video;
		case 6: return torrent;
		case 7: return pdf;
		case 8: return mp3;
		case 9: return msgs;
			
		default:
			return null;
		}	
	}
	
	public ArrayList<Integer> getCsvSize(int num){
		
		switch (num) {
		case 1: return documents_sizes;
		case 2: return images_sizes;
		case 3: return excels_sizes;
		case 4: return ppt_sizes;
		case 5: return video_sizes;
		case 6: return torrent_sizes;
		case 7: return pdf_sizes;
		case 8: return mp3_sizes;
			
		default:
			return null;
		}	
	}
	

}